/**
 * tjftp -- A simple FTP server, using the ANSI C
 * Copyright (C) 2011  degui.chen <degui.chen@qq.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef SOCKETS_H
#define SOCKETS_H

#define TEST_DEBUG 1

#include <string.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

void tj_sockets_debug();

#define tj_sockets_open(domain, type, protocol) _tj_sockets_open(domain, type, protocol, __FILE__, __FUNCTION__, __LINE__, __STDC__)
int _tj_sockets_open(int domain, int type, int protocol, const char* file, const char* fun, int line, int ansi_c);

#define tj_sockets_close(fd) _tj_sockets_close(fd, __FILE__, __FUNCTION__, __LINE__, __STDC__)
void _tj_sockets_close(int fd, const char* file, const char* fun, int line, int ansi_c);

#define accepts_open(fd_socket, addr, addr_len) _accepts_open(fd_socket, addr, addr_len, __FILE__, __FUNCTION__, __LINE__, __STDC__)
int _tj_accepts_open(int fd_socket, struct sockaddr * addr, unsigned int* addr_len, const char* file, const char* fun, int line, int ansi_c);

#define accepts_close(fd) _accepts_close(fd, __FILE__, __FUNCTION__, __LINE__, __STDC__)
void _tj_accepts_close(int fd, const char* file, const char* fun, int line, int ansi_c);

void tj_set_timeout(int fd_socket, int timeout);
void tj_set_reuse(int fd_socket);
void tj_set_buffer(int fd_socket, int value);
void tj_set_broadcast(int fd_socket);
void tj_set_ip_including(int fd_socket);
char* tj_get_local_ip(void);
void tj_get_remote_address(int port, char* ip, struct sockaddr_in* result);
void tj_get_local_address(int port, struct sockaddr_in* result);
int tj_create_tcp_socket();
void tj_tcp_open_connect(int fd, char* ip, int port);
void tj_tcp_open_listen(int fd_socket, int port, int backlog);
int tj_tcp_accept(int fd_socket);
void tj_tcp_send_file(int fd, char* path);
int tj_udp_create_socket();
int tj_udp_bind(int fd_socket, int port);

#endif /* SOCKETS_H */
